﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenCvSharp;

namespace LicenseAutoDetection
{
    class Morphology
    {
        public IplImage DilateMorphology(IplImage src)      // 팽창
        {
            using (IplImage dstImg = src.Clone())
            using (IplConvKernel element = Cv.CreateStructuringElementEx(4, 4, 2, 2, ElementShape.Rect, null)) // 구조 요소 생성
            {
                Cv.Dilate(src, dstImg, element, 1);
                return dstImg.Clone();
            }
        }

        public IplImage ErodeMorphology(IplImage src)       // 침식
        {
            using (IplImage dstImg = src.Clone())
            using (IplConvKernel element = Cv.CreateStructuringElementEx(9, 9, 4, 4, ElementShape.Rect, null))
            {   
                Cv.Erode(src, dstImg, element, 1);
                return dstImg.Clone();
            }
        }

        public IplImage BlackHatMorphology(IplImage src)
        {
            using (IplImage dstImg = src.Clone())
            using (IplImage tmpImg = src.Clone())
            using (IplConvKernel element = Cv.CreateStructuringElementEx(3, 3, 1, 1, ElementShape.Rect, null))
            {
                Cv.MorphologyEx(src, dstImg, tmpImg, element, MorphologyOperation.BlackHat, 1);
                return dstImg.Clone();
            }
        }
    }
}
